{layout name="layout"}
{include file="public/nav"}
<div class="container-fluid" style="text-align: center">
    <h1>留言板管理</h1>
</div>
<div class="container">
    <div class=" row">
        <h3>待审核</h3>
    </div>

    <div class="row">
        <table class="table">
            <caption>审核通过</caption>
            <thead>
            <tr>
                <th>留言id</th>
                <th>留言内容</th>
                <th>留言人姓名</th>
                <th>邮箱</th>
                <th>留言时间</th>
                <th>删除留言</th>
            </tr>
            </thead>
            <tbody>
            {volist name="$messages0", id="message"}
            <tr>
                <td>{$message.msg_id}</td>
                <td>{$message.msg_content}</td>
                <td>{$message.msg_author}</td>
                <td>{$message.msg_author_email}</td>
                <td>{$message.msg_create_time}</td>
                <td><button data-showMsg="{$message.msg_id}" class="btn btn-default showMessage">通过</button></td>
            </tr>
            {/volist}

            </tbody>
        </table>
    </div>

    <br><hr><br>

    <div class=" row">
        <h3>留言板数据</h3>
    </div>

    <br><hr><br>

    <div class="row">
        <table class="table">
            <caption>审核通过</caption>
            <thead>
            <tr>
                <th>留言id</th>
                <th>留言内容</th>
                <th>留言人姓名</th>
                <th>邮箱</th>
                <th>留言时间</th>
                <th>删除留言</th>
            </tr>
            </thead>
            <tbody id="showedMsg">
                {volist name="$messages1", id="message"}
            <tr>
                <td>{$message.msg_id}</td>
                <td>{$message.msg_content}</td>
                <td>{$message.msg_author}</td>
                <td>{$message.msg_author_email}</td>
                <td>{$message.msg_create_time}</td>
                <td><button  data-hideMsg="{$message.msg_id}" class="btn btn-danger hiddenMessage">删除</button></td>
            </tr>
            {/volist}
            </tbody>
        </table>
    </div>

    <br><hr><br>

<!--    <div class="row">-->
<!--        <h3></h3>-->
<!--    </div>-->
</div>

<script>
    $(function () {
        /*通过审核*/
        $(".showMessage").click(function () {
            let messageId = $(this).attr('data-showMsg')
            // let strip = $(this).parent().parent();
            // strip.fadeOut(10)
            // strip.appendTo("#showedMsg")
            $.ajax({
                type: "POST",
                url: "/admin/passMsg/"+messageId,
                success:function (data) {
                    if(data === 1){
                        alert("审核通过成功！")
                        location.href = "/admin/msg"
                        // console.log(data);
                    }else{
                        alert("审核通过失败！")
                        location.href = "/admin/msg"
                    }
                },
                error:function (error) {
                    alert("审核通过失败！")
                    location.href = "/admin/msg"
                    // console.log(error);
                }
            })
        })

        /*删除留言*/
        $(".hiddenMessage").click(function () {
            $(this).parent().parent().fadeOut(10)
            $.ajax({
                type: "POST",
                url: "/admin/delMsg/"+ $(this).attr('data-hideMsg'),
                success:function (data) {
                    if(data === 1){
                        alert("留言删除成功")
                        // console.log(data);
                    }else{
                        alert("留言删除失败")
                        location.href = "/admin/msg"
                    }
                },
                error:function (error) {
                    alert("留言删除失败")
                    location.href = "/admin/msg"
                    // console.log(error);
                }
            })
        })
    })
</script>